#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H

#include "clog.h"

struct cexception
{
	cexception()
	{
	}

	cexception ( int a, int b, string fname )
	{
		int slash = fname.find_last_of ( "/\\" );
		fname = fname.substr ( slash + 1 );
		err_code = a;
		err_line = b;
		cppfile = fname;
		LOGP4 ( "cexception #%d at %d in %s", a, b, fname.c_str() );
	}
	cexception ( int a, int b, string fname, string err_string )
	{
		int slash = fname.find_last_of ( "/\\" );
		fname = fname.substr ( slash + 1 );
		err_code = a;
		err_line = b;
		cppfile = err_string + " @ " + fname;
		LOGP5 ( "cexception #%d [%s] at %d in %s", a, err_string.c_str(), b, fname.c_str() );
	}

	string cppfile;
	i32 err_code;
	i32 err_line;
};

#define EXC    throw cexception(0x00,__LINE__,__FILE__);
#define EXCC(ERR_CODE)   throw cexception(ERR_CODE,__LINE__,__FILE__);
#define EXCEX(ERR_CODE,ERR_STRING)   throw cexception(ERR_CODE,__LINE__,__FILE__,ERR_STRING);

#define FLAG    if (!isFlagOk())throw cexception(0x00,__LINE__,__FILE__)
#define FLAGC(code)    if (!isFlagOk())throw cexception(code,__LINE__,__FILE__)
#define FLAGCS(code,err_str)    if (!isFlagOk())throw cexception(code,__LINE__,__FILE__,err_str)



#endif // EXCEPTIONS_H
